<div class="main-content">
    <div class="section__content section__content--p20">
        <div class="container-fluid">
            <div class="row m-b-30">
                <div class="col-lg-12">
                    <div class="overview-wrap">
                        <h2 class="title-1">系统邮箱设置</h2>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <strong>系统邮箱设置</strong>
                        </div>
                        <div class="card-body">
                            <form class="form-horizontal" role="form" name="form" id="form" method="post" action="index.php?r=admin/config/editemail"
                                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh"
                            >
                                <input type="hidden" name="module" value="email"/>
                                <input type="hidden" name="YII_CSRF_TOKEN" value="<?php echo Yii::app()->request->csrfToken; ?>" />

                                <div class="form-group">
                                    <label class=" form-control-label">发件人姓名</label>
                                    <input type="text" class="form-control "
                                           value="<?php echo $emailconfig['senduser']['content']; ?>" name="senduser" data-bv-notempty="true"
                                           data-bv-notempty-message="发件人姓名是必须的！"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">邮箱账号</label>
                                    <input type="text" class="form-control"
                                           value="<?php echo $emailconfig['sendemail']['content']; ?>" name="sendemail"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">邮件SMTP服务器</label>
                                    <input type="text" class="form-control "
                                           value="<?php echo $emailconfig['emailsmtp']['content']; ?>" name="emailsmtp"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">邮箱密码</label>
                                    <input type="password" class="form-control "
                                           value="<?php echo $emailconfig['emailpwd']['content']; ?>" name="emailpwd"/>
                                </div>


                                <div class="form-group">
                                    <button  type="submit" name="submit" id="submit" class="btn btn-primary btn-lg btn-block">保存</button>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        initPage();
    });
    function initPage() {
        $('#form').bootstrapValidator();
        $('#form').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (formData, jqForm, options) {
                return $('#form').data('bootstrapValidator').isValid();
            },
            success: function (res) {
                if (message(res)) {

                }
            }
        });
    }
</script>
<script>

    function sendEmailTest() {
        mask();
        var testemail = $("input[name=testemail]").val();
        if (isNull(testemail)) {
            $('#testemail').validationEngine('showPrompt', '测试邮箱不能为空');
        } else {
            $('#testemail').validationEngine('hide');
            $.get('index.php?r=admin/config/testEmail', {email: testemail}, function (res) {
                unmask();
                if (res.type == true) {
                    success('测试邮件发送成功');
                } else {
                    alert('邮件发送失败，请检查邮箱设置');
                }
            }, 'json');
        }
    }
    function saveEmailConfig() {
        if ($("#form_editemail").validationEngine('validate')) {
            document.forms['form_editemail'].submit();
        }
    }
</script>